package com.graphhopper.matching;

import com.google.common.collect.Maps;
import com.google.common.geometry.*;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

public class utils {
    public static int Interval_Seconds = 60 * 15;
    public static int Max_Distance= 1500;
    public static int Degree_Threshold = 30;
    public static int Reduce_Seconds = 60 * 5;
    public static int Distance_Threshold =  800;
    public static int Time_Threshold = 60 * 15;
    public static int Outdoor_Radius = 800;
    public static int Indoor_Radius = 200;
    public static int Double_Scale = 4;
    public static int Min_Indoor_Count = 3;
    public static double Outdoor_Confidence = 0.7;
    public static double EARTH_RADIUS = 6367000.0D;
    public static double kEarthCircumferenceMeters = 40075017;
    public static int S2_Dim_Level = 18;

    public static double getDistance (double lonA1,double latA1,double lonA2,double latA2) {
        double lon1 = lonA1* Math.PI /180;
        double lat1 = latA1* Math.PI /180;
        double lon2 = lonA2* Math.PI /180;
        double lat2 = latA2* Math.PI /180;
        double dlon = lon2 - lon1;
        double dlat = lat2 - lat1;
        double a = Math.pow(Math.sin(dlat / 2), 2) + Math.cos(lat1) * Math.cos(lat2) * Math.pow(Math.sin(dlon / 2), 2);
        double c = 2 * Math.asin(Math.sqrt(a));
        return c * 6371 * 1000;
    }

    public static double getDegree(double vertexPointX, double vertexPointY, double point0X, double point0Y, double point1X, double point1Y) {
        //向量的点乘
        double vector = (point0X - vertexPointX) * (point1X - vertexPointX) + (point0Y - vertexPointY) * (point1Y - vertexPointY);
        //向量的模乘
        double sqrt = Math.sqrt(
                (Math.abs((point0X - vertexPointX) * (point0X - vertexPointX)) + Math.abs((point0Y - vertexPointY) * (point0Y - vertexPointY)))
                        * (Math.abs((point1X - vertexPointX) * (point1X - vertexPointX)) + Math.abs((point1Y - vertexPointY) * (point1Y - vertexPointY)))
        );
        //反余弦计算弧度
        double radian = Math.acos(vector / sqrt);
        //弧度转角度制
        return 180 * radian / Math.PI;
    }

    public static double getAngle1(double lat_a, double lng_a, double lat_b, double lng_b) {
        double y = Math.sin(lng_b - lng_a) * Math.cos(lat_b);
        double x = Math.cos(lat_a) * Math.sin(lat_b) - Math.sin(lat_a) * Math.cos(lat_b) * Math.cos(lng_b - lng_a);
        double brng = Math.atan2(y, x);

        brng = Math.toDegrees(brng);
        if (brng < 0)
            brng = brng + 360;
        return brng;
    }

    public static String milli2Date(long milliSecond){
        Date date = new Date();
        date.setTime(milliSecond);
        return new SimpleDateFormat("yyyyMMddHHmmssSSS").format(date);
    }

}
